import json2json from "https://gitee.com/zhangweis/deno-report-tools/raw/master/json2json.ts";
import {Script, OpCode, Word, Dictionary} from './compiler.ts';
import {PathDictionary} from './pathdictionary.ts';
import {RemoteDictionary} from './remotedictionary.ts';
import {CompositeDictionary} from './composite-dictionary.ts'
import {mapdict, opCodes} from './mapdict.ts';
json2json(async (json:any)=> {
    var inputDict:any = mapdict();
    for (var key in json) {
        inputDict['${'+key+'}'] = new OpCode(json[key]);
    }
    var remoteUrls = (json.urls||[]).map((url:string)=>new RemoteDictionary(url));
    var remotes = new CompositeDictionary(remoteUrls);
    var localPaths = (json.paths||[]).map((path:string)=>new PathDictionary(path));
    var locals = new CompositeDictionary(localPaths);
    var script = json.script||Deno.args[0]||"main";
    var expanded = await new Script(script).expand(new CompositeDictionary([inputDict, opCodes(), remotes, locals]));
    return expanded;
})